//
//  KABOperateVC.m
//  kabu
//
//  Created by XiangDongMBP on 2017/4/25.
//  Copyright © 2017年 East. All rights reserved.
//

#import "KABOperateVC.h"
#import "KABRootTabVC.h"

@interface KABOperateVC ()

@property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
@property (weak, nonatomic) IBOutlet UIButton *passBtn;
@property (assign, nonatomic) NSInteger countdown;
@property (strong, nonatomic) NSTimer *timer;

@end

@implementation KABOperateVC

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initNavigationBar];
    [self initSubViews];
}

- (void)initNavigationBar {
    
}

- (void)initSubViews {
    self.bgImgView.image = self.launchImg;
    
    self.passBtn.layer.masksToBounds = YES;
    self.passBtn.layer.cornerRadius = 4;
    [self.passBtn addTarget:self action:@selector(passBtnTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    self.countdown = 5;
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(OneSecondTimerHandle) userInfo:nil repeats:YES];
    [self refreshWholeView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - delegate
#pragma mark - event response
- (void)OneSecondTimerHandle {
    if (--self.countdown < 0) {
        [self.timer invalidate];
        [self jumpToRootVC];
    } else {
        [self refreshWholeView];
    }
}
- (void)passBtnTapped:(UIButton *)btn {
    [self.timer invalidate];
    [self jumpToRootVC];
}

#pragma mark - private methods
- (void)jumpToRootVC {
    [UIApplication sharedApplication].keyWindow.rootViewController = [[KABRootTabVC alloc] init];
    //转场动画
    CATransition *anim = [CATransition animation];
    //    anim.type = @"rippleEffect";
    anim.duration = 0.3;
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
}

- (void)refreshWholeView {
    NSString *title = [NSString stringWithFormat:@"跳过%zds", self.countdown];
    [self.passBtn setTitle:title forState:UIControlStateNormal];
}

#pragma mark - network request
#pragma mark - getters and setters

@end
